package StreamOf;

import java.util.stream.Stream;

/**
 * @author zc
 * @version 1.0
 * @date 2021/9/24 13:43
 */
public class Test7 {
    public static void main(String[] args) {
//        Stream<Integer> stream = Stream.of(6, 4, 6, 7, 3, 9, 8, 10, 12, 14, 14);
////        stream.forEach(System.out::println);
//        //stream.forEach(integer -> System.out.print(integer+" "));
//        Stream<Integer> integerStream = stream.filter(s -> s > 5);
//        //integerStream.forEach(integer -> System.out.print(integer+" "));
//        Stream<Integer> skip = integerStream.skip(2);
//        skip.forEach(integer -> System.out.print(integer+" "));

        /*
        筛选与切片
　　filter：过滤流中的某些元素
　　limit(n)：获取n个元素
　　skip(n)：跳过n元素，配合limit(n)可实现分页
　　distinct：通过流中元素的 hashCode() 和 equals() 去除重复元素
         */
        Stream<Integer> stream = Stream.of(6, 4, 6, 7, 3, 9, 8, 10, 12, 14, 14);

        Stream<Integer> newStream = stream.filter(s -> s > 5) //6 6 7 9 8 10 12 14 14
                .distinct() //6 7 9 8 10 12 14
                .skip(2) //9 8 10 12 14
                .limit(2); //9 8
        newStream.forEach(System.out::println);

    }
}
